home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / prbgi097.zip / BGIDEMO.INC < prev    next >
Text File  |  1992-12-15  |  38KB  |  1,255 lines

  1. #include <STDio.h>
  2. #include <CONIO.h>
  3. #include <math.h>
  4. #include <DOS.h>
  5.  
  6. #ifdef _cplusplus
  7.    #define min(a,b)    (((a) < (b)) ? (a) : (b))
  8. #endif
  9.  
  10. #define TRUE   1        /* Define some handy constants   */
  11. #define FALSE  0        /* Define some handy constants   */
  12. #define PI  3.14159     /* Define a value for PI   */
  13. #define ON  1        /* Define some handy constants   */
  14. #define OFF 0        /* Define some handy constants   */
  15.  
  16. char *Fonts[] = {
  17.   "DefaultFont",   "TriplexFont",   "SmallFont",
  18.   "SansSerifFont", "GothicFont"
  19. };
  20.  
  21. char *LineStyles[] = {
  22.   "SolidLn",  "DottedLn",  "CenterLn",  "DashedLn",  "UserBitLn"
  23. };
  24.  
  25. char *FillStyles[] = {
  26.   "EmptyFill",  "SolidFill",      "LineFill",      "LtSlashFill",
  27.   "SlashFill",  "BkSlashFill",    "LtBkSlashFill", "HatchFill",
  28.   "XHatchFill", "InterleaveFill", "WideDotFill",   "CloseDotFill"
  29. };
  30.  
  31. char *TextDirect[] = {
  32.   "HorizDir",  "VertDir"
  33. };
  34.  
  35. char *HorizJust[] = {
  36.   "LeftText",   "CenterText",   "RightText"
  37. };
  38.  
  39. char *VertJust[] = {
  40.   "BottomText",  "CenterText",  "TopText"
  41. };
  42.  
  43. struct PTS {
  44.   int x, y;
  45. }; /* Structure to hold vertex points  */
  46.  
  47. int   xasp_,yasp_;
  48. int    ErrorCode;    /* Reports any graphics errors      */
  49.  
  50.  
  51.  
  52. /*                         */
  53. /* REPORTSTATUS: Report the current configuration of the system   */
  54. /* after the auto-detect initialization.           */
  55. /*                         */
  56.  
  57. int ReportStatus(void far * GraphDriverPtr)
  58. {
  59.   struct viewporttype     viewinfo; /* Params for inquiry procedures*/
  60.   struct linesettingstype lineinfo;
  61.   struct fillsettingstype fillinfo;
  62.   struct textsettingstype textinfo;
  63.   struct palettetype   palette;
  64.  
  65.   const char *driver, *mode;        /* Strings for driver and mode   */
  66.   int x, y;
  67.   int xRes,yRes;
  68.  
  69.   getviewsettings( &viewinfo );
  70.   getlinesettings( &lineinfo );
  71.   getfillsettings( &fillinfo );
  72.   gettextsettings( &textinfo );
  73.   getpalette( &palette );
  74.  
  75.   x = 10;
  76.   y = 4;
  77.  
  78.   MainWindow( "Status report after InitGraph" );
  79.   settextjustify( LEFT_TEXT, TOP_TEXT );
  80.  
  81.   driver = getdrivername();
  82.   mode = BGI_getmodename(BGI_getgraphmode(0)); /* get current setting     */
  83.  
  84.   gprintf( &x, &y, "Graphics device    : %-20s (%d)", driver, *(int*)GraphDriverPtr );
  85.   gprintf( &x, &y, "Graphics mode      : %-20s (%d)", mode, BGI_getgraphmode(0) );
  86.   gprintf( &x, &y, "Screen resolution  : ( 0, 0, %d, %d )", getmaxx(), getmaxy() );
  87.  
  88.   gprintf( &x, &y, "Current view port  : ( %d, %d, %d, %d )",
  89.   viewinfo.left, viewinfo.top, viewinfo.right, viewinfo.bottom );
  90.   gprintf( &x, &y, "Clipping           : %s", viewinfo.clip ? "ON" : "OFF" );
  91.  
  92.   gprintf( &x, &y, "Current position   : ( %d, %d )", getx(), gety() );
  93.   gprintf( &x, &y, "Colors available   : %d", MaxColors );
  94.   gprintf( &x, &y, "Current color      : %d", getcolor() );
  95.  
  96.   gprintf( &x, &y, "Line style         : %s", LineStyles[ lineinfo.linestyle ] );
  97.   gprintf( &x, &y, "Line thickness     : %d", lineinfo.thickness );
  98.  
  99.   gprintf( &x, &y, "Current fill style : %s", FillStyles[ fillinfo.pattern ] );
  100.   gprintf( &x, &y, "Current fill color : %d", fillinfo.color );
  101.  
  102.   gprintf( &x, &y, "Current font       : %s", Fonts[ textinfo.font ] );
  103.   gprintf( &x, &y, "Text direction     : %s", TextDirect[ textinfo.direction ] );
  104.   gprintf( &x, &y, "Character size     : %d", textinfo.charsize );
  105.   gprintf( &x, &y, "Horizontal justify : %s", HorizJust[ textinfo.horiz ] );
  106.   gprintf( &x, &y, "Vertical justify   : %s", VertJust[ textinfo.vert ] );
  107.  
  108.   if ( BGI_getresolution(&xRes,&yRes) == 0 )
  109.   {
  110.      gprintf( &x, &y, "X resolution [ppi] : %d", xRes );
  111.      gprintf( &x, &y, "Y resolution [ppi] : %d", yRes );
  112.   }
  113.  
  114.   Pause();           /* Pause for user to read screen*/
  115.   return(0);
  116.  
  117. }
  118.  
  119.  
  120.  
  121. int static Textfont;
  122.  
  123. int TextDump2(void far * UnusedPointer)
  124. {
  125.   static int CGASizes[]  = {
  126.     1, 3, 7, 3, 3   };
  127.   static int NormSizes[] = {
  128.     1, 4, 7, 4, 4   };
  129.  
  130.   char buffer[80];
  131.   int ch, wwidth, lwidth, size;
  132.   struct viewporttype vp;
  133.  
  134.     sprintf( buffer, "%s Character Set", Fonts[Textfont] );
  135.     MainWindow( buffer );     /* Display fontname as banner */
  136.     getviewsettings( &vp );      /* read current viewport   */
  137.  
  138.     settextjustify( LEFT_TEXT, TOP_TEXT );
  139.     moveto( 2, 3 );
  140.  
  141.     buffer[1] = '\0';                   /* Terminate string             */
  142.     wwidth = vp.right - vp.left; /* Determine the window width */
  143.     lwidth = textwidth( "H" );          /* Get average letter width     */
  144.  
  145.     if( Textfont == DEFAULT_FONT ){
  146.       changetextstyle( Textfont, HORIZ_DIR, 1 );
  147.       ch = 0;
  148.       while( ch < 256 ){      /* For each possible character   */
  149.    buffer[0] = ch;      /* Put character into a string   */
  150.    outtext( buffer );      /* send string to screen   */
  151.    if( (getx() + lwidth) > wwidth )
  152.      moveto( 2, gety() + textheight("H") + 3 );
  153.    ++ch;          /* Goto the next character */
  154.       }
  155.     }
  156.     else{
  157.  
  158.       size = (MaxY < 200) ? CGASizes[Textfont] : NormSizes[Textfont];
  159.       changetextstyle( Textfont, HORIZ_DIR, size );
  160.  
  161.       ch = '!';                         /* Begin at 1st printable       */
  162.       while( ch < 127 ){      /* For each printable character */
  163.    buffer[0] = ch;      /* Put character into a string   */
  164.    outtext( buffer );      /* send string to screen   */
  165.    if( (lwidth+getx()) > wwidth )   /* Are we still in window? */
  166.      moveto( 2, gety()+textheight("H")+3 );
  167.    ++ch;          /* Goto the next character */
  168.       }
  169.  
  170.     }
  171.  
  172.     Pause();            /* Pause until user acks   */
  173.     return(0);
  174. }  /* end of TextDump2 */
  175.  
  176. /*                         */
  177. /* TEXTDUMP: Display the all the characters in each of the  */
  178. /* available fonts.                 */
  179. /*                         */
  180.  
  181. void TextDump()
  182. {
  183.   for( Textfont=0 ; Textfont<5 ; ++Textfont ){  /* For each available font */
  184.    //DrawAndPrint(TextDump2,NULL);
  185.   }               /* End of FONT loop     */
  186. }
  187.  
  188. /*                         */
  189. /* BAR3DDEMO: Display a 3-D bar chart on the screen.     */
  190. /*                         */
  191.  
  192. int Bar3DDemo(void far * UnusedPointer)
  193. {
  194.   static int barheight[] = {
  195.     1, 3, 5, 4, 3, 2, 1, 5, 4, 2, 3   };
  196.   struct viewporttype vp;
  197.   int xstep, ystep;
  198.   int i, j, h, color, bheight;
  199.   char buffer[10];
  200.  
  201.   MainWindow( "Bar 3-D / Rectangle Demonstration" );
  202.  
  203.   srand(0);
  204.   h = 3 * textheight( "H" );
  205.   getviewsettings( &vp );
  206.   settextjustify( CENTER_TEXT, TOP_TEXT );
  207.   changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
  208.   outtextxy( MaxX/2, 6, "These are 3-D Bars" );
  209.   changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
  210.   setviewport( vp.left+50, vp.top+40, vp.right-50, vp.bottom-10, 1 );
  211.   getviewsettings( &vp );
  212.  
  213.   line( h, h, h, vp.bottom-vp.top-h );
  214.   line( h, (vp.bottom-vp.top)-h, (vp.right-vp.left)-h, (vp.bottom-vp.top)-h );
  215.   xstep = ((vp.right-vp.left) - (2*h)) / 10;
  216.   ystep = ((vp.bottom-vp.top) - (2*h)) / 5;
  217.   j = (vp.bottom-vp.top) - h;
  218.   settextjustify( CENTER_TEXT, CENTER_TEXT );
  219.  
  220.   for( i=0 ; i<6 ; ++i ){
  221.     line( h/2, j, h, j );
  222.     itoa( i, buffer, 10 );
  223.     outtextxy( 0, j, buffer );
  224.     j -= ystep;
  225.   }
  226.  
  227.   j = h;
  228.   settextjustify( CENTER_TEXT, TOP_TEXT );
  229.  
  230.   for( i=0 ; i<11 ; ++i ){
  231.     color = random( MaxColors-1 ) +1;
  232.     setfillstyle( i+1, color );
  233.     line( j, (vp.bottom-vp.top)-h, j, (vp.bottom-vp.top-3)-(h/2) );
  234.     itoa( i, buffer, 10 );
  235.     outtextxy( j, (vp.bottom-vp.top)-(h/2), buffer );
  236.     if( i != 10 ){
  237.       bheight = (vp.bottom-vp.top) - h - 1;
  238.       bar3d( j, (vp.bottom-vp.top-h)-(barheight[i]*ystep), j+xstep, bheight,
  239.              min(getmaxy(),getmaxx())/25, 1 );
  240.     }
  241.     j += xstep;
  242.   }
  243.  
  244.   Pause();           /* Pause for user's response    */
  245.   return(0);
  246.  
  247. }
  248.  
  249. /*                         */
  250. /* RANDOMBARS: Display random bars           */
  251. /*                         */
  252.  
  253. int RandomBars(void far * UnusedPointer)
  254. {
  255.   int color;
  256.   int i;
  257.  
  258.   MainWindow( "Random Bars" );
  259.   /* StatusLine( "Esc aborts or press a key..." ); */
  260.   srand(0);
  261.   for ( i=0; i<10; i++ )
  262.   {
  263.     color = random( MaxColors-1 )+1;
  264.     setcolor( color );
  265.     setfillstyle( random(11)+1, color );
  266.     bar3d( random( getmaxx() ), random( getmaxy() ),
  267.       random( getmaxx() ), random( getmaxy() ), 0, OFF);
  268.   }
  269.  
  270.   Pause();           /* Pause for user's response    */
  271.   return(0);
  272.  
  273. }
  274.  
  275.  
  276.  
  277.  
  278. /*                         */
  279. /* TEXTDEMO2: Show given font in several sizes to the user.    */
  280. /*                         */
  281.  
  282. int TextDemo2(void far * UnusedPointer)
  283. {
  284.   int charsize[] = {
  285.     1, 3, 7, 3, 4   };
  286.   int size;
  287.   int h, x, y, i;
  288.   struct viewporttype vp;
  289.   char buffer[80];
  290.  
  291.     sprintf( buffer, "%s Demonstration", Fonts[Textfont] );
  292.     MainWindow( buffer );
  293.     getviewsettings( &vp );
  294.  
  295.     changetextstyle( Textfont, VERT_DIR, charsize[Textfont] );
  296.     settextjustify( CENTER_TEXT, BOTTOM_TEXT );
  297.     outtextxy( 2*textwidth("M"), vp.bottom - 2*textheight("M"), "Vertical" );
  298.  
  299.     changetextstyle( Textfont, HORIZ_DIR, charsize[Textfont] );
  300.     settextjustify( LEFT_TEXT, TOP_TEXT );
  301.     outtextxy( 2*textwidth("M"), 2, "Horizontal" );
  302.  
  303.     settextjustify( CENTER_TEXT, CENTER_TEXT );
  304.     x = (vp.right - vp.left) / 2;
  305.     y = textheight( "H" );
  306.  
  307.     for( i=1 ; i<5 ; ++i ){      /* For each of the sizes */
  308.       size = (Textfont == SMALL_FONT) ? i+3 : i;
  309.       changetextstyle( Textfont, HORIZ_DIR, size );
  310.       h = textheight( "H" );
  311.       y += h;
  312.       sprintf( buffer, "Size %d", size );
  313.       outtextxy( x, y, buffer );
  314.  
  315.     }
  316.  
  317.     if( Textfont != DEFAULT_FONT ){    /* Show user declared Textfont size */
  318.       y += h / 2;       /* Move down the screen    */
  319.       settextjustify( CENTER_TEXT, TOP_TEXT );
  320.       setusercharsize( 5, 6, 3, 2 );
  321.       changetextstyle( Textfont, HORIZ_DIR, USER_CHAR_SIZE );
  322.       outtextxy( (vp.right-vp.left)/2, y, "User Defined Size" );
  323.     }
  324.  
  325.     Pause();            /* Pause to let user look  */
  326.     return(0);
  327. }  /* end of TextDemo2 */
  328.  
  329.  
  330. /*                         */
  331. /* TEXTDEMO: Show each font in several sizes to the user.      */
  332. /*                         */
  333.  
  334. void TextDemo(void)
  335. {
  336.  
  337.   for( Textfont=0 ; Textfont<5 ; ++Textfont ){  /* For each of the four fonts */
  338.    // DrawAndPrint(TextDemo2,NULL);
  339.   }               /* End of FONT loop     */
  340.  
  341. }
  342.  
  343. /*                         */
  344. /* COLORDEMO: Display the current color palette on the screen. */
  345. /*                         */
  346.  
  347. int ColorDemo(void far * UnusedPointer)
  348. {
  349.   struct viewporttype vp;
  350.   int color, height, width;
  351.   int x, y, i, j;
  352.   char cnum[5];
  353.  
  354.   MainWindow( "Color Demonstration" );  /* Show demonstration name      */
  355.  
  356.   color = 1;
  357.   getviewsettings( &vp );     /* Get the current window size   */
  358.   width  = 2 * ( (vp.right+1) / 16 );     /* Get box dimensions      */
  359.   height = 2 * ( (vp.bottom-10) / 10 );
  360.  
  361.   x = width / 2;
  362.   y = height / 2; /* Leave 1/2 box border    */
  363.  
  364.   for( j=0 ; j<3 ; ++j ){     /* Row loop       */
  365.  
  366.     for( i=0 ; i<5 ; ++i ){      /* Column loop       */
  367.  
  368.       setfillstyle(SOLID_FILL, color); /* Set to solid fill in color */
  369.       setcolor( color );      /* Set the same border color  */
  370.  
  371.       bar( x, y, x+width, y+height );  /* Draw the rectangle      */
  372.       rectangle( x, y, x+width, y+height );  /* outline the rectangle   */
  373.  
  374.       if( color == BLACK ){      /* If box was black...     */
  375.    setcolor( WHITE );      /* Set drawing color to white */
  376.    rectangle( x, y, x+width, y+height );  /* Outline black in white*/
  377.       }
  378.  
  379.       itoa( color, cnum, 10 );      /* Convert # to ASCII      */
  380.       outtextxy( x+(width/2), y+height+4, cnum );  /* Show color #   */
  381.  
  382.       color = ++color % MaxColors;  /* Advance to the next color  */
  383.       x += (width / 2) * 3;      /* move the column base    */
  384.     }          /* End of Column loop      */
  385.  
  386.     y += (height / 2) * 3;    /* move the row base    */
  387.     x = width / 2;         /* reset column base    */
  388.   }               /* End of Row loop      */
  389.  
  390.   Pause();           /* Pause for user's response    */
  391.   return(0);
  392.  
  393. }
  394.  
  395. /*                         */
  396. /* ARCDEMO: Display a random pattern of arcs on the screen */
  397. /* until the user says enough.               */
  398. /*                         */
  399.  
  400. int ArcDemo(void far * UnusedPointer)
  401. {
  402.   int mradius;          /* Maximum radius allowed  */
  403.   int eangle;           /* Random end angle of Arc */
  404.   struct arccoordstype ai;    /* Used to read Arc Cord info */
  405.    int   i;
  406.  
  407.   MainWindow( "Arc Demonstration" );
  408.   /* StatusLine( "ESC Aborts - Press a Key to stop" ); */
  409.  
  410.   mradius = MaxY / 10;        /* Determine the maximum radius */
  411.  
  412.   srand(0); /* to draw always the same ( for the same MaxX,MaxY ) */
  413.   for ( i=0; i<100; i++ )
  414.   {
  415.     setcolor( random( MaxColors - 1 ) + 1 ); /* Randomly select a color */
  416.     eangle = random( 358 ) + 1;  /* Select an end angle     */
  417.      arc( random(MaxX), random(MaxY), random(eangle), eangle, mradius );
  418.     getarccoords( &ai );      /* Read Cord data    */
  419.     line( ai.x, ai.y, ai.xstart, ai.ystart ); /* line from start to center */
  420.     line( ai.x, ai.y,   ai.xend,   ai.yend ); /* line from end to center   */
  421.   }
  422.  
  423.   Pause();           /* Wait for user's response     */
  424.   return(0);
  425.  
  426. }
  427.  
  428. /*                         */
  429. /* CIRCLEDEMO: Display a random pattern of circles on the screen  */
  430. /* until the user says enough.               */
  431. /*                         */
  432.  
  433. int CircleDemo(void far * UnusedPointer)
  434. {
  435.   int mradius;          /* Maximum radius allowed  */
  436.   int i;
  437.  
  438.   MainWindow( "Circle Demonstration" );
  439.   /* StatusLine( "ESC Aborts - Press a Key to stop" ); */
  440.  
  441.   srand(0);
  442.   mradius = MaxY / 10;        /* Determine the maximum radius */
  443.  
  444.   for ( i=0; i<100; i++ )
  445.   {
  446.     setcolor( random( MaxColors - 1 ) + 1 ); /* Randomly select a color */
  447.     circle( random(MaxX), random(MaxY), random(mradius) );
  448.   }               /* End of WHILE not KBHIT  */
  449.  
  450.   Pause();           /* Wait for user's response     */
  451.   return(0);
  452.  
  453. }
  454.  
  455. /*                         */
  456. /* PIEDEMO: Display a pie chart on the screen.        */
  457. /*                         */
  458.  
  459. #define adjasp( y )  ((int)(AspectRatio * (double)(y)))
  460. #define torad( d )   (( (double)(d) * PI ) / 180.0 )
  461.  
  462. int PieDemo(void far * UnusedPointer)
  463. {
  464.   struct viewporttype vp;
  465.   int xcenter, ycenter, radius, lradius;
  466.   int x, y;
  467.   double radians, piesize;
  468.  
  469.   MainWindow( "Pie Chart Demonstration" );
  470.  
  471.   getviewsettings( &vp );     /* Get the current viewport   */
  472.   xcenter = (vp.right - vp.left) / 2;  /* Center the Pie horizontally   */
  473.   ycenter = (vp.bottom - vp.top) / 2+20;/* Center the Pie vertically */
  474.   radius  = (vp.bottom - vp.top) / 3;  /* It will cover 2/3rds screen   */
  475.   piesize = (vp.bottom - vp.top) / 4.0; /* Optimum height ratio of pie  */
  476.  
  477.   while( (AspectRatio*radius) < piesize ) ++radius;
  478.  
  479.   lradius = radius + ( radius / 5 );   /* Labels placed 20% farther  */
  480.  
  481.   changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
  482.   settextjustify( CENTER_TEXT, TOP_TEXT );
  483.   outtextxy( MaxX/2, 6, "This is a Pie Chart" );
  484.   changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 1 );
  485.   settextjustify( CENTER_TEXT, TOP_TEXT );
  486.  
  487.   setfillstyle( SOLID_FILL, RED );
  488.   pieslice( xcenter+10, ycenter-adjasp(10), 0, 90, radius );
  489.   radians = torad( 45 );
  490.   x = xcenter + (int)( cos( radians ) * (double)lradius );
  491.   y = ycenter - (int)( sin( radians ) * (double)lradius * AspectRatio );
  492.   settextjustify( LEFT_TEXT, BOTTOM_TEXT );
  493.   outtextxy( x, y, "25 %" );
  494.  
  495.   setfillstyle( WIDE_DOT_FILL, GREEN );
  496.   pieslice( xcenter, ycenter, 90, 135, radius );
  497.   radians = torad( 113 );
  498.   x = xcenter + (int)( cos( radians ) * (double)lradius );
  499.   y = ycenter - (int)( sin( radians ) * (double)lradius * AspectRatio );
  500.   settextjustify( RIGHT_TEXT, BOTTOM_TEXT );
  501.   outtextxy( x, y, "12.5 %" );
  502.  
  503.   setfillstyle( INTERLEAVE_FILL, YELLOW );
  504.   settextjustify( RIGHT_TEXT, CENTER_TEXT );
  505.   pieslice( xcenter-10, ycenter, 135, 225, radius );
  506.   radians = torad( 180 );
  507.   x = xcenter + (int)( cos( radians ) * (double)lradius );
  508.   y = ycenter - (int)( sin( radians ) * (double)lradius * AspectRatio );
  509.   settextjustify( RIGHT_TEXT, CENTER_TEXT );
  510.   outtextxy( x, y, "25 %" );
  511.  
  512.   setfillstyle( HATCH_FILL, BLUE );
  513.   pieslice( xcenter, ycenter, 225, 360, radius );
  514.   radians = torad( 293 );
  515.   x = xcenter + (int)( cos( radians ) * (double)lradius );
  516.   y = ycenter - (int)( sin( radians ) * (double)lradius * AspectRatio );
  517.   settextjustify( LEFT_TEXT, TOP_TEXT );
  518.   outtextxy( x, y, "37.5 %" );
  519.  
  520.   Pause();           /* Pause for user's response    */
  521.   return(0);
  522.  
  523. }
  524.  
  525. /*                         */
  526. /* BARDEMO: Draw a 2-D bar chart using Bar and Rectangle.      */
  527. /*                         */
  528.  
  529. int BarDemo(void far * UnusedPointer)
  530. {
  531.   int barheight[] = {
  532.     1, 3, 5, 2, 4   };
  533.   int styles[]   = {
  534.     1, 3, 10, 5, 9, 1   };
  535.   int xstep, ystep;
  536.   int sheight, swidth;
  537.   int i, j, h;
  538.   struct viewporttype vp;
  539.   char buffer[40];
  540.  
  541.   MainWindow( "Bar / Rectangle Demostration" );
  542.   srand(0);
  543.   h = 3 * textheight( "H" );
  544.   getviewsettings( &vp );
  545.   settextjustify( CENTER_TEXT, TOP_TEXT );
  546.   changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
  547.   outtextxy( MaxX /2, 6, "These are 2-D Bars" );
  548.   changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
  549.   setviewport( vp.left+50, vp.top+30, vp.right-50, vp.bottom-10, 1 );
  550.  
  551.   getviewsettings( &vp );
  552.   sheight = vp.bottom - vp.top;
  553.   swidth  = vp.right  - vp.left;
  554.  
  555.   line( h, h, h, sheight-h );
  556.   line( h, sheight-h, sheight-h, sheight-h );
  557.   ystep = (sheight - (2*h) ) / 5;
  558.   xstep = (swidth  - (2*h) ) / 5;
  559.   j = sheight - h;
  560.   settextjustify( CENTER_TEXT, CENTER_TEXT );
  561.  
  562.   for( i=0 ; i<6 ; ++i ){
  563.     line( h/2, j, h, j );
  564.     itoa( i, buffer, 10 );
  565.     outtextxy( 0, j, buffer );
  566.     j -= ystep;
  567.   }
  568.  
  569.   j = h;
  570.   settextjustify( CENTER_TEXT, TOP_TEXT );
  571.   for( i=0 ; i<6 ; ++i ){
  572.     setfillstyle( styles[i], random(MaxColors-1)+1 );
  573.     line( j, sheight - h, j, sheight- 3 - (h/2) );
  574.     itoa( i, buffer, 10 );
  575.     outtextxy( j, sheight - (h/2), buffer );
  576.     if( i != 5 ){
  577.       bar( j, (sheight-h)-(barheight[i] * ystep), j+xstep, sheight-h-1 );
  578.       rectangle( j, (sheight-h)-(barheight[i] * ystep), j+xstep, sheight-h);
  579.     }
  580.     j += xstep;
  581.   }
  582.  
  583.   Pause();
  584.   return(0);
  585.  
  586. }
  587.  
  588. /*                         */
  589. /* LINERELDEMO: Display pattern using moverel and linerel cmds.   */
  590. /*                         */
  591.  
  592. int LineRelDemo(void far * UnusedPointer)
  593. {
  594.   struct viewporttype vp;
  595.   int h, w, dx, dy, cx, cy;
  596.   struct PTS outs[7];
  597.  
  598.  
  599.   MainWindow( "MoveRel / LineRel Demonstration" );
  600.   StatusLine( "Press any key to continue, ESC to Abort" );
  601.  
  602.   getviewsettings( &vp );
  603.   cx = (vp.right  - vp.left) / 2;   /* Center of the screen coords   */
  604.   cy = (vp.bottom - vp.top ) / 2;
  605.  
  606.   h  = (vp.bottom - vp.top ) / 8;
  607.   w  = (vp.right  - vp.left) / 9;
  608.  
  609.   dx = 2 * w;
  610.   dy = 2 * h;
  611.  
  612.   setcolor( BLACK );
  613.  
  614.   setfillstyle( SOLID_FILL, BLUE );
  615.   bar( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /* Draw backgnd */
  616.  
  617.   outs[0].x = cx -  dx;
  618.   outs[0].y = cy -  dy;
  619.   outs[1].x = cx - (dx-w);
  620.   outs[1].y = cy - (dy+h);
  621.   outs[2].x = cx +  dx;
  622.   outs[2].y = cy - (dy+h);
  623.   outs[3].x = cx +  dx;
  624.   outs[3].y = cy +  dy;
  625.   outs[4].x = cx + (dx-w);
  626.   outs[4].y = cy + (dy+h);
  627.   outs[5].x = cx -  dx;
  628.   outs[5].y = cy + (dy+h);
  629.   outs[6].x = cx -  dx;
  630.   outs[6].y = cy -  dy;
  631.  
  632.   setfillstyle( SOLID_FILL, WHITE );
  633.   fillpoly( 7, (int far *)outs );
  634.  
  635.   outs[0].x = cx - (w/2);
  636.   outs[0].y = cy + h;
  637.   outs[1].x = cx + (w/2);
  638.   outs[1].y = cy + h;
  639.   outs[2].x = cx + (w/2);
  640.   outs[2].y = cy - h;
  641.   outs[3].x = cx - (w/2);
  642.   outs[3].y = cy - h;
  643.   outs[4].x = cx - (w/2);
  644.   outs[4].y = cy + h;
  645.  
  646.   setfillstyle( SOLID_FILL, BLUE );
  647.   fillpoly( 5, (int far *)outs );
  648.  
  649.   /*  Draw a Tesseract object on the screen using the LineRel and */
  650.   /*  MoveRel drawing commands.              */
  651.  
  652.   moveto( cx-dx, cy-dy );
  653.   linerel(  w, -h );
  654.   linerel(  3*w,  0 );
  655.   linerel(   0,  5*h );
  656.   linerel( -w, h );
  657.   linerel( -3*w,  0 );
  658.   linerel(   0, -5*h );
  659.  
  660.   moverel( w, -h );
  661.   linerel(   0,  5*h );
  662.   linerel( w+(w/2), 0 );
  663.   linerel(   0, -3*h );
  664.   linerel( w/2,   -h );
  665.   linerel( 0, 5*h );
  666.  
  667.   moverel(  0, -5*h );
  668.   linerel( -(w+(w/2)), 0 );
  669.   linerel( 0, 3*h );
  670.   linerel( -w/2, h );
  671.  
  672.   moverel( w/2, -h );
  673.   linerel( w, 0 );
  674.  
  675.   moverel( 0, -2*h );
  676.   linerel( -w, 0 );
  677.  
  678.   Pause();           /* Wait for user's response     */
  679.   return(0);
  680.  
  681. }
  682.  
  683. /*                         */
  684. /* PUTPIXELDEMO: Display a pattern of random dots on the screen   */
  685. /* and pick them back up again.              */
  686. /*                         */
  687.  
  688. int PutPixelDemo(void far * UnusedPointer)
  689. {
  690.   int seed = 1958;
  691.   int i, x, y, h, w, color;
  692.   struct viewporttype vp;
  693.  
  694.   MainWindow( "PutPixel / GetPixel Demonstration" );
  695.  
  696.   getviewsettings( &vp );
  697.   h = vp.bottom - vp.top;
  698.   w = vp.right - vp.left;
  699.  
  700.   srand( seed );        /* Restart random # function  */
  701.  
  702.   for( i=0 ; i<5000 ; ++i ){     /* Put 5000 pixels on screen  */
  703.     x = 1 + random( w - 1 );     /* Generate a random location */
  704.     y = 1 + random( h - 1 );
  705.     color = random( MaxColors );
  706.     putpixel( x, y, color );
  707.   }
  708.  
  709.   srand( seed );        /* Restart Random # at same # */
  710.  
  711.   for( i=0 ; i<5000 ; ++i ){     /* Take the 5000 pixels off   */
  712.     x = 1 + random( w - 1 );     /* Generate a random location */
  713.     y = 1 + random( h - 1 );
  714.     color = getpixel( x, y );    /* Read the color pixel    */
  715.      /* color = random( MaxColors ); */
  716.     if( color == random( MaxColors ) )    /* Used to keep RANDOM in sync   */
  717.       putpixel( x, y, 0 );    /* Write pixel to BLACK    */
  718.     else
  719.       x=color;
  720.   }
  721.  
  722.   Pause();           /* Wait for user's response     */
  723.   return(0);
  724.  
  725. }
  726.  
  727. /*                         */
  728. /*   PUTIMAGEDEMO                   */
  729. /*                         */
  730. int PutImageDemo(void far * UnusedPointer)
  731. {
  732.   static int r     = 20;
  733.   static int StartX = 100;
  734.   static int StartY = 50;
  735.  
  736.   struct viewporttype vp;
  737.   int PauseTime, x, y, ulx, uly, lrx, lry, size, i, width, height, step;
  738.   void *Saucer;
  739.  
  740.   MainWindow("GetImage / PutImage Demonstration");
  741.   getviewsettings( &vp );
  742.  
  743.   /* Draw Saucer */
  744.   setfillstyle( SOLID_FILL, getmaxcolor() );
  745.   fillellipse(StartX, StartY, r, (r/3)+2);
  746.   ellipse(StartX, StartY-4, 190, 357, r, r/3);
  747.  
  748.   line(StartX+7, StartY-6, StartX+10, StartY-12);
  749.   circle(StartX+10, StartY-12, 2);
  750.   line(StartX-7, StartY-6, StartX-10, StartY-12);
  751.   circle(StartX-10, StartY-12, 2);
  752.  
  753.  
  754.   /* Read saucer image */
  755.   ulx = StartX-(r+1);
  756.   uly = StartY-14;
  757.   lrx = StartX+(r+1);
  758.   lry = StartY+(r/3)+3;
  759.   width = lrx - ulx + 1;
  760.   height = lry - uly + 1;
  761.   size = imagesize(ulx, uly, lrx, lry);
  762.  
  763.   Saucer = malloc( size );
  764.   getimage(ulx, uly, lrx, lry, Saucer);
  765.   putimage(ulx, uly, Saucer, XOR_PUT);
  766.  
  767. /* Plot some "stars"  */
  768.   for ( i=0 ; i<1000; ++i )
  769.     putpixel(random(MaxX), random(MaxY), random( MaxColors-1 )+1);
  770.   x = MaxX / 2;
  771.   y = MaxY / 2;
  772.   PauseTime = 70;
  773.  
  774.   /* until a key is hit */
  775.   for ( i=0 ; i<20; ++i )
  776.   {
  777.     /* Draw the Saucer */
  778.     putimage(x, y, Saucer, XOR_PUT);           /*  draw image  */
  779.     delay(PauseTime);
  780.     putimage(x, y, Saucer, XOR_PUT);           /* erase image  */
  781.  
  782.     /* Move Saucer */
  783.  
  784.     step = random( 2*r );
  785.     if ((step/2) % 2 != 0 )
  786.       step = -1 * step;
  787.     x = x + step;
  788.     step = random( r );
  789.     if ((step/2) % 2 != 0 )
  790.       step = -1 * step;
  791.     y = y + step;
  792.  
  793.     if (vp.left + x + width - 1 > vp.right)
  794.       x = vp.right-vp.left-width + 1;
  795.     else
  796.       if (x < 0)
  797.    x = 0;
  798.     if (vp.top + y + height - 1 > vp.bottom)
  799.       y = vp.bottom-vp.top-height + 1;
  800.     else
  801.       if (y < 0)
  802.    y = 0;
  803.   }
  804.   free( Saucer );
  805.   Pause();
  806.   return(0);
  807. }
  808.  
  809.  
  810. /*                         */
  811. /* LINETODEMO: Display a pattern using moveto and lineto commands. */
  812. /*                         */
  813.  
  814. #define MAXPTS 15
  815.  
  816. int LineToDemo(void far * UnusedPointer)
  817. {
  818.   struct viewporttype vp;
  819.   struct PTS points[MAXPTS];
  820.   int i, j, h, w, xcenter, ycenter;
  821.   int radius, angle, step;
  822.   double  rads;
  823.  
  824.   MainWindow( "MoveTo / LineTo Demonstration" );
  825.  
  826.   getviewsettings( &vp );
  827.   h = vp.bottom - vp.top;
  828.   w = vp.right - vp.left;
  829.  
  830.   xcenter = w / 2;         /* Determine the center of circle */
  831.   ycenter = h / 2;
  832.   radius  = (h - 30) / (AspectRatio * 2);
  833.   step     = 360 / MAXPTS;    /* Determine # of increments  */
  834.  
  835.   angle = 0;            /* Begin at zero degrees   */
  836.   for( i=0 ; i<MAXPTS ; ++i ){      /* Determine circle intercepts   */
  837.     rads = (double)angle * PI / 180.0; /* Convert angle to radians   */
  838.     points[i].x = xcenter + (int)( cos(rads) * radius );
  839.     points[i].y = ycenter - (int)( sin(rads) * radius * AspectRatio );
  840.     angle += step;         /* Move to next increment  */
  841.   }
  842.  
  843.   circle( xcenter, ycenter, radius );  /* Draw bounding circle    */
  844.  
  845.   for( i=0 ; i<MAXPTS ; ++i ){      /* Draw the cords to the circle */
  846.     for( j=i ; j<MAXPTS ; ++j ){ /* For each remaining intersect */
  847.       moveto(points[i].x, points[i].y); /* Move to beginning of cord */
  848.       lineto(points[j].x, points[j].y); /* Draw the cord    */
  849.     }
  850.   }
  851.  
  852.   Pause();           /* Wait for user's response     */
  853.   return(0);
  854.  
  855. }
  856.  
  857. /*                         */
  858. /* LINESTYLEDEMO: Display a pattern using all of the standard  */
  859. /* line styles that are available.           */
  860. /*                         */
  861.  
  862. int LineStyleDemo(void far * UnusedPointer)
  863. {
  864.   int style, step;
  865.   int x, y, w;
  866.   struct viewporttype vp;
  867.   char buffer[40];
  868.  
  869.   MainWindow( "Pre-defined line styles" );
  870.  
  871.   getviewsettings( &vp );
  872.   w = vp.right - vp.left;
  873.  
  874.   x = 35;
  875.   y = 10;
  876.   step = w / 11;
  877.  
  878.   settextjustify( LEFT_TEXT, TOP_TEXT );
  879.   outtextxy( x, y, "Normal Width" );
  880.  
  881.   settextjustify( CENTER_TEXT, TOP_TEXT );
  882.  
  883.   for( style=0 ; style<4 ; ++style ){
  884.     setlinestyle( style, 0, NORM_WIDTH );
  885.     line( x, y+20, x, vp.bottom-40 );
  886.     itoa( style, buffer, 10 );
  887.     outtextxy( x, vp.bottom-30, buffer );
  888.     x += step;
  889.   }
  890.  
  891.   x += 2 * step;
  892.  
  893.   settextjustify( LEFT_TEXT, TOP_TEXT );
  894.   outtextxy( x, y, "Thick Width" );
  895.   settextjustify( CENTER_TEXT, TOP_TEXT );
  896.  
  897.   for( style=0 ; style<4 ; ++style ){
  898.     setlinestyle( style, 0, THICK_WIDTH );
  899.     line( x, y+20, x, vp.bottom-40 );
  900.     itoa( style, buffer, 10 );
  901.     outtextxy( x, vp.bottom-30, buffer );
  902.     x += step;
  903.   }
  904.  
  905.   settextjustify( LEFT_TEXT, TOP_TEXT );
  906.  
  907.   Pause();           /* Wait for user's response     */
  908.   return(0);
  909.  
  910. }
  911.  
  912. /*                         */
  913. /* CRTMODEDEMO: Demonstrate the effects of the change mode  */
  914. /* commands on the current screen.           */
  915. /*                         */
  916.  
  917. int CRTModeDemo(void far * UnusedPointer)
  918. {
  919.   struct viewporttype vp;
  920.   int mode;
  921.  
  922.   MainWindow( "SetGraphMode / RestoreCRTMode demo" );
  923.   getviewsettings( &vp );
  924.   mode = getgraphmode();
  925.   settextjustify( CENTER_TEXT, CENTER_TEXT );
  926.  
  927.   outtextxy( (vp.right-vp.left)/2, (vp.bottom-vp.top)/2,
  928.   "Now you are in graphics mode..." );
  929.   StatusLine( "Press any key for text mode..." );
  930.   getch();
  931.  
  932.   restorecrtmode();
  933.   printf( "Now you are in text mode.\n\n" );
  934.   printf( "Press any key to go back to graphics..." );
  935.   getch();
  936.  
  937.   setgraphmode( mode );
  938.   MainWindow( "SetGraphMode / RestoreCRTMode demo" );
  939.   settextjustify( CENTER_TEXT, CENTER_TEXT );
  940.   outtextxy( (vp.right-vp.left)/2, (vp.bottom-vp.top)/2,
  941.   "Back in Graphics Mode..." );
  942.  
  943.   Pause();           /* Wait for user's response     */
  944.   return(0);
  945.  
  946. }
  947.  
  948. /*                         */
  949. /* USERLINESTYLEDEMO: Display line styles showing the user  */
  950. /* defined line style functions.             */
  951. /*                         */
  952.  
  953. int UserLineStyleDemo(void far * UnusedPointer)
  954. {
  955.   int x, y, i, h, flag;
  956.   unsigned int style;
  957.   struct viewporttype vp;
  958.  
  959.   MainWindow( "User defined line styles" );
  960.  
  961.   getviewsettings( &vp );
  962.   h = vp.bottom - vp.top;
  963.  
  964.   x = 4;
  965.   y = 10;
  966.   style = 0;
  967.   i = 0;
  968.  
  969.   settextjustify( CENTER_TEXT, TOP_TEXT );
  970.   flag = TRUE;          /* Set the bits in this pass  */
  971.  
  972.   while( x < vp.right-2 ){    /* Draw lines across the screen */
  973.  
  974.     if( flag )          /* If flag, set bits...    */
  975.       style = style | (1 << i);  /*    Set the Ith bit in word */
  976.     else          /* If no flag, clear bits  */
  977.     style = style & !(0x8000 >> i); /*    Clear the Ith bit in word */
  978.  
  979.     setlinestyle( USERBIT_LINE, style, NORM_WIDTH );
  980.     line( x, y, x, h-y );     /* Draw the new line pattern  */
  981.  
  982.     x += 5;          /* Move the X location of line   */
  983.     i = ++i % 16;       /* Advance to next bit pattern   */
  984.  
  985.     if( style == 0xffff ){    /* Are all bits set?    */
  986.       flag = FALSE;        /*   begin removing bits   */
  987.       i = 0;            /* Start with whole pattern   */
  988.     }
  989.     else{            /* Bits not all set...     */
  990.       if( style == 0 )        /* Are all bits clear?     */
  991.    flag = TRUE;         /*   begin setting bits    */
  992.     }
  993.   }
  994.  
  995.   settextjustify( LEFT_TEXT, TOP_TEXT );
  996.  
  997.   Pause();           /* Wait for user's response     */
  998.   return(0);
  999.  
  1000. }
  1001.  
  1002. /*                         */
  1003. /* FILLSTYLEDEMO: Display the standard fill patterns available.   */
  1004. /*                         */
  1005.  
  1006. int FillStyleDemo(void far * UnusedPointer)
  1007. {
  1008.   int h, w, style;
  1009.   int i, j, x, y;
  1010.   struct viewporttype vp;
  1011.   char buffer[40];
  1012.  
  1013.   MainWindow( "Pre-defined Fill Styles" );
  1014.  
  1015.   getviewsettings( &vp );
  1016.   w = 2 * ((vp.right  +  1) / 13);
  1017.   h = 2 * ((vp.bottom - 10) / 10);
  1018.  
  1019.   x = w / 2;
  1020.   y = h / 2;      /* Leave 1/2 blk margin    */
  1021.   style = 0;
  1022.  
  1023.   for( j=0 ; j<3 ; ++j ){     /* Three rows of boxes     */
  1024.     for( i=0 ; i<4 ; ++i ){      /* Four column of boxes    */
  1025.       setfillstyle(style, MaxColors-1); /* Set the fill style and WHITE */
  1026.       bar( x, y, x+w, y+h );     /* Draw the actual box     */
  1027.       rectangle( x, y, x+w, y+h );  /* Outline the box      */
  1028.       itoa( style, buffer, 10 ); /* Convert style 3 to ASCII   */
  1029.       outtextxy( x+(w / 2), y+h+4, buffer );
  1030.       ++style;          /* Go on to next style #   */
  1031.       x += (w / 2) * 3;       /* Go to next column    */
  1032.     }          /* End of coulmn loop      */
  1033.     x = w / 2;          /* Put base back to 1st column   */
  1034.     y += (h / 2) * 3;         /* Advance to next row     */
  1035.   }               /* End of Row loop      */
  1036.  
  1037.   settextjustify( LEFT_TEXT, TOP_TEXT );
  1038.  
  1039.   Pause();           /* Wait for user's response     */
  1040.   return(0);
  1041.  
  1042. }
  1043.  
  1044. /*                         */
  1045. /* FILLPATTERNDEMO: Demonstrate how to use the user definable  */
  1046. /* fill patterns.                   */
  1047. /*                         */
  1048.  
  1049. int FillPatternDemo(void far * UnusedPointer)
  1050. {
  1051.   int style;
  1052.   int h, w;
  1053.   int x, y, i, j;
  1054.   char buffer[40];
  1055.   struct viewporttype vp;
  1056.   static char patterns[][8] = {
  1057.     { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 },
  1058.     { 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC },
  1059.     { 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F },
  1060.     { 0x00, 0x10, 0x28, 0x44, 0x28, 0x10, 0x00, 0x00 },
  1061.     { 0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00 },
  1062.     { 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00 },
  1063.     { 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00 },
  1064.     { 0x00, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x00 },
  1065.     { 0x00, 0x00, 0x22, 0x08, 0x00, 0x22, 0x1C, 0x00 },
  1066.     { 0xFF, 0x7E, 0x3C, 0x18, 0x18, 0x3C, 0x7E, 0xFF },
  1067.     { 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 0x00 },
  1068.     { 0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00 }
  1069.   };
  1070.  
  1071.   MainWindow( "User Defined Fill Styles" );
  1072.  
  1073.   getviewsettings( &vp );
  1074.   w = 2 * ((vp.right  +  1) / 13);
  1075.   h = 2 * ((vp.bottom - 10) / 10);
  1076.  
  1077.   x = w / 2;
  1078.   y = h / 2;      /* Leave 1/2 blk margin    */
  1079.   style = 0;
  1080.  
  1081.   for( j=0 ; j<3 ; ++j ){     /* Three rows of boxes     */
  1082.     for( i=0 ; i<4 ; ++i ){      /* Four column of boxes    */
  1083.       setfillpattern( &patterns[style][0], MaxColors-1 );
  1084.       bar( x, y, x+w, y+h );     /* Draw the actual box     */
  1085.       rectangle( x, y, x+w, y+h );  /* Outline the box      */
  1086.       itoa( style, buffer, 10 ); /* Convert style 3 to ASCII   */
  1087.       outtextxy( x+(w / 2), y+h+4, buffer );
  1088.       ++style;          /* Go on to next style #   */
  1089.       x += (w / 2) * 3;       /* Go to next column    */
  1090.     }          /* End of coulmn loop      */
  1091.     x = w / 2;          /* Put base back to 1st column   */
  1092.     y += (h / 2) * 3;         /* Advance to next row     */
  1093.   }               /* End of Row loop      */
  1094.  
  1095.   settextjustify( LEFT_TEXT, TOP_TEXT );
  1096.  
  1097.   Pause();           /* Wait for user's response     */
  1098.   return(0);
  1099.  
  1100. }
  1101.  
  1102.  
  1103. /*                         */
  1104. /* POLYDEMO: Display a random pattern of polygons on the screen   */
  1105. /* until the user says enough.               */
  1106. /*                         */
  1107.  
  1108. #define MaxPts    6     /* Maximum # of pts in polygon   */
  1109.  
  1110. int PolyDemo(void far * UnusedPointer)
  1111. {
  1112.   struct PTS poly[ MaxPts ];     /* Space to hold datapoints   */
  1113.   int color;            /* Current drawing color   */
  1114.   int i,j;
  1115.  
  1116.   MainWindow( "DrawPoly / FillPoly Demonstration" );
  1117.   /* StatusLine( "ESC Aborts - Press a Key to stop" ); */
  1118.  
  1119.   srand(0);
  1120.   for ( j=0; j<5; j++ )
  1121.   {
  1122.  
  1123.     color = 1 + random( MaxColors-1 ); /* Get a random color # (no blk)*/
  1124.     setfillstyle( random(10), color ); /* Set a random line style */
  1125.     setcolor( color );        /* Set the desired color   */
  1126.  
  1127.     for( i=0 ; i<(MaxPts-1) ; i++ ){   /* Determine a random polygon */
  1128.       poly[i].x = random( MaxX );   /* Set the x coord of point   */
  1129.       poly[i].y = random( MaxY );   /* Set the y coord of point   */
  1130.     }
  1131.  
  1132.     poly[i].x = poly[0].x;    /* last point = first point   */
  1133.     poly[i].y = poly[1].y;
  1134.  
  1135.     fillpoly( MaxPts, (int far *)poly );    /* Draw the actual polygon      */
  1136.   }               /* End of WHILE not KBHIT  */
  1137.  
  1138.   Pause();           /* Wait for user's response     */
  1139.   return(0);
  1140.  
  1141. }
  1142.  
  1143.  
  1144. /*                         */
  1145. /* SAYGOODBYE: Give a closing screen to the user before leaving.  */
  1146. /*                         */
  1147.  
  1148. int SayGoodbye(void far * UnusedPointer)
  1149. {
  1150.   struct viewporttype viewinfo;  /* Structure to read viewport */
  1151.   int h, w;
  1152.  
  1153.   MainWindow( "== Finale ==" );
  1154.  
  1155.   getviewsettings( &viewinfo );  /* Read viewport settings  */
  1156.   changetextstyle( TRIPLEX_FONT, HORIZ_DIR, 4 );
  1157.   settextjustify( CENTER_TEXT, CENTER_TEXT );
  1158.  
  1159.   h = viewinfo.bottom - viewinfo.top;
  1160.   w = viewinfo.right  - viewinfo.left;
  1161.   outtextxy( w/2, h/2, "That's all, folks!" );
  1162.  
  1163.   StatusLine( "Press any key to EXIT" );
  1164.   getch();
  1165.  
  1166.   cleardevice();        /* Clear the graphics screen  */
  1167.    return(0);
  1168. }
  1169. /*                         */
  1170. /* MAINWINDOW: Establish the main window for the demo and set  */
  1171. /* a viewport for the demo code.             */
  1172. /*                         */
  1173.  
  1174. void MainWindow( char *header )
  1175. {
  1176.   int height;
  1177.  
  1178.   cleardevice();        /* Clear graphics screen   */
  1179.   setcolor( MaxColors - 1 );     /* Set current color to white */
  1180.   setviewport( 0, 0, MaxX, MaxY, 1 );  /* Open port to full screen   */
  1181.  
  1182.   changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
  1183.   height = textheight( "H" );           /* Get basic text height        */
  1184.  
  1185.   settextjustify( CENTER_TEXT, TOP_TEXT );
  1186.   outtextxy( MaxX/2, 2, header );
  1187.   setviewport( 0, height+4, MaxX, MaxY-(height+4), 1 );
  1188.   DrawBorder();
  1189.   setviewport( 1, height+5, MaxX-1, MaxY-(height+5), 1 );
  1190.  
  1191. }
  1192.  
  1193. /*                         */
  1194. /* STATUSLINE: Display a status line at the bottom of the screen. */
  1195. /*                         */
  1196.  
  1197. void StatusLine( char *msg )
  1198. {
  1199.   int height;
  1200.   setviewport( 0, 0, MaxX, MaxY, 1 );  /* Open port to full screen   */
  1201.   setcolor( MaxColors - 1 );     /* Set current color to white */
  1202.  
  1203.   changetextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
  1204.   settextjustify( CENTER_TEXT, TOP_TEXT );
  1205.   setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
  1206.   setfillstyle( EMPTY_FILL, 0 );
  1207.  
  1208.   height = textheight( "H" );           /* Detemine current height      */
  1209.   bar( 0, MaxY-(height+4), MaxX, MaxY );
  1210.   rectangle( 0, MaxY-(height+4), MaxX, MaxY );
  1211.   outtextxy( MaxX/2, MaxY-(height+2), msg );
  1212.   setviewport( 1, height+5, MaxX-1, MaxY-(height+5), 1 );
  1213. }
  1214.  
  1215. /*                         */
  1216. /* DRAWBORDER: Draw a solid single line around the current  */
  1217. /* viewport.                     */
  1218. /*                         */
  1219.  
  1220. void DrawBorder(void)
  1221. {
  1222.   struct viewporttype vp;
  1223.  
  1224.   setcolor( MaxColors - 1 );     /* Set current color to white */
  1225.  
  1226.   setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
  1227.  
  1228.   getviewsettings( &vp );
  1229.   rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top );
  1230.  
  1231. }
  1232.  
  1233. /*                         */
  1234. /* GPRINTF: Used like PRINTF except the output is sent to the  */
  1235. /* screen in graphics mode at the specified co-ordinate.    */
  1236. /*                         */
  1237.  
  1238. int gprintf( int *xloc, int *yloc, char *fmt, ... )
  1239. {
  1240.   va_list  argptr;         /* Argument list pointer   */
  1241.   char str[140];        /* Buffer to build sting into */
  1242.   int cnt;           /* Result of SPRINTF for return */
  1243.  
  1244.   va_start( argptr, fmt );    /* Initialize va_ functions   */
  1245.  
  1246.   cnt = vsprintf( str, fmt, argptr );  /* prints string to buffer */
  1247.   outtextxy( *xloc, *yloc, str );   /* Send string in graphics mode */
  1248.   *yloc += textheight( "H" ) + 2;       /* Advance to next line         */
  1249.  
  1250.   va_end( argptr );        /* Close va_ functions     */
  1251.  
  1252.   return( cnt );        /* Return the conversion count   */
  1253.  
  1254. }
  1255.